package com.ktmall.ktmalluijava.controller;

import com.ktmall.ktmalluijava.utils.OssUtil;
import com.ktmall.ktmalluijava.utils.ResMsg;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/9 下午1:11
 */
@RestController
@RequestMapping("/file")
public class UploadController {

    @Resource
    private OssUtil ossUtil;

    @PostMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile image) {
        String imageUrl;
        try {
            imageUrl = ossUtil.upload(image);
        } catch (IOException e) {
            return ResMsg.error("上传失败", e);
        }
        return ResMsg.success("上传成功", imageUrl);
    }
}
